﻿@inject IStringLocalizer<DisplayFormatString> Localizer

<div class="row g-3">
    <div class="col-12 col-sm-6">@Localizer["FormatStringettingText"] <code class="ms-1">FormatString</code></div>
    <div class="col-12 col-sm-6">
        <Display Value="DateTime.Now" FormatString="yyyy-MM-dd" />
    </div>
    <div class="col-12 col-sm-6">@Localizer["FormatStringettingText"] <code class="ms-1">Formatter</code></div>
    <div class="col-12 col-sm-6">
        <Display Value="DateTime.Now" FormatterAsync="@DateTimeFormatter" />
    </div>
</div>
<p class="mt-3">@((MarkupString)Localizer["FormatStringP"].Value)</p>
<div class="row g-3">
    <div class="col-12 col-sm-6">@Localizer["FormatStringettingText"] <code class="ms-1">Formatter</code></div>
    <div class="col-12 col-sm-6">
        <Display Value="@ByteArray" FormatterAsync="@ByteArrayFormatter" />
    </div>
</div>

@code {
    private byte[] ByteArray { get; set; } = { 0x01, 0x12, 0x34, 0x56 };

    private static Task<string> DateTimeFormatter(DateTime source) => Task.FromResult(source.ToString("yyyy-MM-dd"));

    private static async Task<string> ByteArrayFormatter(byte[] source)
    {
        await Task.Delay(10);
        return Convert.ToBase64String(source);
    }
}
